1 using System;
2 using
UnityEngine;
3
4 public
class ClickDetector : MonoBehaviour
5 {
6
7     
void Update()
8     {
9         
// if this player is not "it", the player can't tag anyone, so don't do anything on collision
10         
if (PhotonNetwork.player.ID != GameLogic.playerWhoIsIt)
11         {
12             
return;
13         }
14
15         
if (Input.GetButton("Fire1"))
16         {
17             GameObject goPointedAt = RaycastObject(Input.mousePosition);
18
19             
if (goPointedAt != null && goPointedAt != this.gameObject && goPointedAt.name.Equals("monsterprefab(Clone)", StringComparison.OrdinalIgnoreCase))
20             {
21                 PhotonView rootView = goPointedAt.transform.root.GetComponent<PhotonView>();
22                 GameLogic.TagPlayer(rootView.owner.ID);
23             }
24         }
25     }
26
27     
private GameObject RaycastObject(Vector2 screenPos)
28     {
29         RaycastHit info;
30         #
if UNITY_3_5
31         Camera cam = Camera.mainCamera;
32         #
else
33         Camera cam = Camera.main;
34         #endif
35
36         
if (Physics.Raycast(cam.ScreenPointToRay(screenPos), out info, 200))
37         {
38             
return info.collider.gameObject;
39         }
40
41         
return null;
42     }
43 }


if this player is not "it", the player can't tag anyone, so don't do anything on collision




Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.551 lượt xem

Gõ tìm kiếm nhanh...